package com.example.wblog.dao;

import com.example.wblog.model.User;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;

@Mapper
public interface UserDAO {
    String TABLE_NAME = " user ";
    String INSERT_FIELD = " name, password, salt, head_url, role ";
    String SELECT_FIELD = " id, " + INSERT_FIELD;

    @Insert({"insert into", TABLE_NAME, "(", INSERT_FIELD, ") values (#{name}, #{password}, #{salt}, #{headUrl}, #{role})"})
    int add(User user);

    @Select({"select", SELECT_FIELD, "from", TABLE_NAME, "where id=#{id}"})
    User selectById(int id);

    @Select({"select", SELECT_FIELD, "from", TABLE_NAME, "where name=#{name}"})
    User selectByName(String name);
}
